
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>plsql-core: messages</title>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    </head>
    <body>
        <h1>plsql-core: messages</h1>
        
        <h2>Overview</h2>
        
        <p>
            The messages module defines a standard interface for sending 
            application messages.
        </p>
        
        <p>
            This module provides a "default" implementation that sends 
            messages to the event mediator. 
            <br/>
            Using this implementation, anyone interested in receiving messages 
            can just register as an observer of the 'message' event.
        </p> 


        <h2>Example</h2>
        
        The following example (which can be run in SQL*Plus) creates the package 
        <code>messages_demo</code> to receive 'message' events.
        <br/>
        Note: you will need to have built the logger, event_mediator and 
        messages modules first.
        <br/>

        <pre>
            -- create the demo package spec
            CREATE OR REPLACE PACKAGE messages_demo 
            IS
              PROCEDURE add_message(
                p_level IN VARCHAR2,
                p_summary IN VARCHAR2,
                p_detail IN VARCHAR2
              );
            END;
            /
            
            -- create the demo package body
            CREATE OR REPLACE PACKAGE BODY messages_demo 
            IS
              PROCEDURE add_message(
                p_level IN VARCHAR2,
                p_summary IN VARCHAR2,
                p_detail IN VARCHAR2
              )
              IS
              BEGIN
                DBMS_OUTPUT.PUT_LINE(
                  'Start of messages_demo.add_message');
                  
                DBMS_OUTPUT.PUT_LINE(
                  'p_level=' || p_level ||
                  ', p_summary=' || p_summary ||
                  ', p_detail=' || p_detail);
                  
              END;
              
            END;
            /
            
            -- register the demo package as an observer of the 'message' event
            BEGIN
              event_mediator.add_observer('message', 'messages_demo');
            END;
            /
            
            -- enable dbms_output
            SET SERVEROUTPUT ON SIZE 1000000
            
            -- send a couple of message via the message package
            BEGIN
              messages.add_message(
                messages.message_level_debug, 'summary one', 'detail one');
                
              messages.add_message(
                messages.message_level_info, 'summary 2', 'detail 2');
                
            END;
            /
        </pre>

        The following output should be produced by the PL/SQL block that
        sends a couple of message via the message package.
        <pre>
            Start of messages_demo.add_message
            p_level=DEBUG, p_summary=summary one, p_detail=detail one
            Start of messages_demo.add_message
            p_level=INFO, p_summary=summary 2, p_detail=detail 2
        </pre>

    </body>
</html>
